package com.example.t2;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        try {
            Context packageContext = createPackageContext("com.example.t1", Context.CONTEXT_IGNORE_SECURITY);
            SharedPreferences a = packageContext.getSharedPreferences("a", MODE_PRIVATE);
            String packageName = packageContext.getPackageName();
            Log.d("fsss", "onCreate: "+packageName);
            SharedPreferences haha = packageContext.getSharedPreferences("t1", MODE_PRIVATE);
            String string = haha.getString("haha", "没找到");
            Log.d("fsss", "onCreate: "+string);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
